<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        div {
            margin: 200px;
        }
        
        span {
            display: inline-block;
            width: 40px;
            height: 40px;
            background-color: #333;
            font-size: 20px;
            color: #fff;
            text-align: center;
            line-height: 40px;
        }
    </style>
</head>

<body>
    <div>
        <span class="hour"></span>
        <span class="minute"></span>
        <span class="second"></span>
    </div>
    <script>
        // 获取元素 
        //时
        var hour = document.querySelector('.hour'); 
        //分
        var minute = document.querySelector('.minute'); 
        //秒
        var second = document.querySelector('.second'); 
        //目标时间的总毫秒数
        var inputTime = +new Date('2023-3-25'); 
        // 先调用一次这个函数，防止第一次刷新页面有空白 
        countDown(); 
        // 开启定时器
        setInterval(countDown, 1000);

        function countDown() {
            //当前时间的总毫秒数
            var nowTime = +new Date(); 
            //目标时间-当前时间的总秒数
            var times = (inputTime - nowTime) / 1000; 
            //时
            var h = parseInt(times / 60 / 60 % 24); 
            h = h < 10 ? '0' + h : h;
            //剩余小时赋值给时盒子
            hour.innerHTML = h; 
            //分
            var m = parseInt(times / 60 % 60); 
            m = m < 10 ? '0' + m : m;
            //剩余分赋值给分盒子
            minute.innerHTML = m;
            //秒
            var s = parseInt(times % 60); 
            s = s < 10 ? '0' + s : s;
            //剩余秒赋值给秒盒子
            second.innerHTML = s;
        }
    </script>
</body>

</html